#@head("用户列表")
#define main()
#end
<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">帐号</label>
								<div class="layui-input-block">
									<input type="text" name="attr.logn_acct" placeholder="请输入帐号" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">姓名</label>
								<div class="layui-input-block">
									<input type="text" name="attr.real_name" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">用户类型</label>
								<div class="layui-input-block">
									<select name="attr.user_type">
										<option value="-1">--请选择--</option>
										<option value="1">系统管理员</option>
										<option value="2">普通用户</option>
										<option value="5">API用户</option>
						                <option value="3">前台用户</option>
						                <option value="4">第三方用户</option>
						                <option value="9">其他用户</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-menu" lay-submit lay-filter="LAY-user-front-search">查询</button>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div style="padding-bottom: 10px;">
							<button class="layui-btn layuiadmin-btn-menu" data-type="batchdel">删除</button>
							<button class="layui-btn layuiadmin-btn-menu" data-type="add">添加</button>
							<button class="layui-btn layuiadmin-btn-menu" data-type="reset">重置密码</button>
						</div>
						<table id="LAY-system-user-manage" lay-filter="LAY-system-user-manage">
						</table>
						<script type="text/html" id="table-system-user-operate">
							<a class="layui-btn layui-btn-xs" lay-event="role"><i class="layui-icon layui-icon-user"></i>角色</a>
							<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="auth"><i class="layui-icon layui-icon-auz"></i>操作权限</a>
							<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
							<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			  			</script>
					</div>
				</div>
			</div>
		</div>
	</div>
	#@layui()
	#define use()
		use(["index", "form", "table"], function(){
			var $ = layui.$,
			form = layui.form,
			table = layui.table,
			a = layui.admin;
			
			table.render({
		        elem: "#LAY-system-user-manage",
		        url: layui.setter.base + "/system/user/list",
		        cols: [[
		            {type: "checkbox", fixed: "left"},
		            {field: "id", title: "ID", width: 60, sort: !0},
			        {field: "org_name", title: "所属机构"},
		            {field: "logn_acct", title: "登录帐号"},
			        {field: "real_name", title: "真实姓名"},
			        {field: "user_type", title: "用户类型", templet: function(d){
			        	if(d.user_type == 1){
			        		return "管理员";
		                }else if(d.user_type == 2){
		                	return "普通用户";
		                }else if(d.user_type == 3){
		                	return "前台用户";
		                }else if(d.user_type == 4){
		                	return "第三方用户";
		                }else if(d.user_type == 5){
		                	return "API用户";
		                }
			        }},
			        {field: "avatar", title: "头像", width: 100, templet: function(d){
			        	return "<img style='display: inline-block; height: 100%;' src='" + d.avatar + "'>";
			        }},
			        {field: "email", title: "Email", width: 180},
			        {field: "phone", title: "手机号"},
			        {field: "status", title: "状态", templet: function(d){
			        	if(d.status == 1){
			        		return "正常";
		                }else if(d.status == 2){
		                	return "冻结";
		                }
			        }},
			        {field: "create_time", title: "创建时间", width: 200, sort: !0},
			        {title: "操作", width: 300, align: "center", fixed: "right", toolbar: "#table-system-user-operate"}
		        ]],
		        page: {
			        layout: ["limit", "count", "prev", "page", "next", "skip"], //自定义分页布局
			        groups: 1, //只显示 1 个连续页码
			        first: false, //不显示首页
			        last: false, //不显示尾页
		        },
		        limit: 30,
		        height: "full-220",
		        skin: "row", //行边框风格
		        even: true, //开启隔行背景
		        text: {
		            none: "暂无相关数据"
		        }
		    }),
		    table.on("tool(LAY-system-user-manage)", function(e) {
		    	var data = e.data;
		    	if ("role" === e.event) {
		    		layer.open({
		                type: 2,
		                title: "设置角色",
		                content: layui.setter.base + "/system/user/setRole?uId=" + data.id,
		                maxmin: true,
    					area: ["520px", "520px"],
		                btn: ["确定", "取消"],
		                yes: function(e, t) {
		                    var l = window["layui-layer-iframe" + e],
		                    r = "LAY-user-role-front-submit",
		                    n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
		                    //监听提交
		                    l.layui.form.on("submit(" + r + ")", function(t) {
		                        a.req({
		                            url: layui.setter.base + "/system/user/saveRole?uId=" + data.id,
		                            data: t.field,
		                            done: function(res){
		        						layer.msg(res.msg, {icon: 1});
		        						table.reload("LAY-system-user-manage");
		    	                        layer.close(e);
		        					}
		                        });
		                    }),
		                    n.trigger("click")
		                },
		                success: function(e, t) {}
		            });
		    	} else if ("auth" === e.event) {
		    		layer.open({
		                type: 2,
		                title: "设置操作权限",
		                content: layui.setter.base + "/system/user/setAuth?uId=" + data.id,
		                maxmin: true,
    					area: ["560px", "520px"],
		                btn: ["确定", "取消"],
		                yes: function(e, t) {
		                    var l = window["layui-layer-iframe" + e],
		                    r = "LAY-user-auth-front-submit",
		                    n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
		                    //监听提交
		                    l.layui.form.on("submit(" + r + ")", function(t) {
		                        a.req({
		                            url: layui.setter.base + "/system/user/saveAuht?uId=" + data.id,
		                            data: t.field,
		                            done: function(res){
		        						layer.msg(res.msg, {icon: 1});
		        						table.reload("LAY-system-user-manage");
		    	                        layer.close(e);
		        					}
		                        });
		                    }),
		                    n.trigger("click")
		                },
		                success: function(e, t) {}
		            });
		    	} else if ("del" === e.event) {
		            layer.confirm("真的删除行么", function(t) {
		            	a.req({
				            url: layui.setter.base + "/system/user/delete",
		                    data: {"ids": data.id},
		                    done: function(res){
		            			layer.msg(res.msg, {icon: 1});
		   						table.reload("LAY-system-user-manage");
		                        layer.close(t)
		   					}
				        });
		            });
		        } else if ("edit" === e.event) {
		            layer.open({
		                type: 2,
		                title: "编辑用户",
		                content: layui.setter.base + "/system/user/form?id=" + data.id,
		                maxmin: true,
    					area: ["600px", "550px"],
		                btn: ["确定", "取消"],
		                yes: function(e, t) {
		                    var l = window["layui-layer-iframe" + e],
		                    r = "LAY-user-front-submit",
		                    n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
		                    //监听提交
		                    l.layui.form.on("submit(" + r + ")", function(t) {
		                        a.req({
		                            url: layui.setter.base + "/system/user/save",
		                            data: t.field,//获取提交的字段
		                            done: function(res){
		        						layer.msg(res.msg, {icon: 1});
		        						table.reload("LAY-system-user-manage");//数据刷新
		    	                        layer.close(e);//关闭弹层
		        					}
		                        });
		                    }),
		                    n.trigger("click")
		                },
		                success: function(e, t) {}
		            });
		        }
		    });
			
			//监听搜索
			form.on("submit(LAY-user-front-search)", function(data){
				var field = data.field;
				//执行重载
				table.reload("LAY-system-user-manage", {
					where: field
				});
			});
			
			//事件
			var active = {
				batchdel: function(){
					var checkStatus = table.checkStatus("LAY-system-user-manage"),
					checkData = checkStatus.data; //得到选中的数据
					if(checkData.length === 0){
						return layer.msg("请选择数据");
					}
					//获取选中的id
					var ids = new Array();
					if(checkData.length>0){
						for(var i=0; i < checkData.length; i++){
							ids.push(checkData[i].id);
						}
					}
					layer.confirm("确定删除吗？", function(index) {
				        a.req({
				            url: layui.setter.base + "/system/user/delete",
		                    data: {"ids": ids.join(",")},
		                    done: function(res){
		            			layer.msg(res.msg, {icon: 1});
		   						table.reload("LAY-system-user-manage");
		   						layer.close(index);
		   					}
				        });
		      		});
    			},
    			add: function(){
    				layer.open({
    					type: 2,
    					title: "添加用户",
    					content: layui.setter.base + "/system/user/form",
		                maxmin: true,
    					area: ["600px", "550px"],
    					btn: ["确定", "取消"],
    					yes: function(e, t){
    						var l = window["layui-layer-iframe" + e],
    						r = "LAY-user-front-submit",
    						n = t.find("iframe").contents().find("#" + r);
		                    if (n.length == 0) {
								return;
							}
    						l.layui.form.on("submit("+ r + ")", function(t){
	    						a.req({
	    							url: layui.setter.base + "/system/user/save",
	    							data: t.field,
	    							done: function(res){
	    								layer.msg(res.msg, {icon: 1});
	    								table.reload("LAY-system-user-manage");
	    								layer.close(e);
	    							}
	    						});
	    					});
	   						n.trigger("click");
    					}
    				});
    			},
    			reset: function(){
					var checkStatus = table.checkStatus("LAY-system-user-manage"),
					checkData = checkStatus.data; //得到选中的数据
					if(checkData.length === 0){
						return layer.msg("请选择数据");
					}
					//获取选中的id
					var ids = new Array();
					if(checkData.length>0){
						for(var i=0; i < checkData.length; i++){
							ids.push(checkData[i].id);
						}
					}
					layer.confirm("确定要重置密码？", function(index) {
				        a.req({
				            url: layui.setter.base + "/system/user/restPwd",
		                    data: {"ids": ids.join(",")},
		                    done: function(res){
		            			layer.msg(res.msg, {icon: 1});
		   						layer.close(index);
		   					}
				        });
		      		});
    			}
			};
	    	$(".layui-btn.layuiadmin-btn-menu").on("click", function(){
	    		var type = $(this).data("type");
	    		active[type] ? active[type].call(this) : "";
	    	});
	    });
	#end
</body>
</html>